package com.wb.base.refreshview;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wb.base.R;


public class LoadView extends LinearLayout {

    private View llNoNetWork;
    private View llLoading;
    private View llNoData, llNone;
    private View viewHintLeft, viewHintRight;
    private TextView tvNoData;

    public LoadView(Context context) {
        this(context, null);
    }

    public LoadView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView();
        loading();
    }

    private void initView() {
        View view = View.inflate(getContext(), R.layout.load_more_view, this);
        llNoNetWork = view.findViewById(R.id.llNoNetwork);
        llNoData = view.findViewById(R.id.llNoData);
        llLoading = view.findViewById(R.id.llLoading);
        llNone = view.findViewById(R.id.llNone);
        viewHintLeft = view.findViewById(R.id.viewHintLeft);
        viewHintRight = view.findViewById(R.id.viewHintRight);
        tvNoData = (TextView) view.findViewById(R.id.tvNoData);
    }


    public void noData() {

        llNoNetWork.setVisibility(View.GONE);
        llLoading.setVisibility(View.GONE);
        llNoData.setVisibility(View.VISIBLE);
    }

    public void loading() {
        llNoNetWork.setVisibility(View.GONE);
        llNoData.setVisibility(View.GONE);
        llLoading.setVisibility(View.VISIBLE);
    }

    public void noNetWork() {
        llLoading.setVisibility(View.GONE);
        llNoData.setVisibility(View.GONE);
        llNoNetWork.setVisibility(View.VISIBLE);
    }

    public void none() {
        llLoading.setVisibility(View.GONE);
        llNoData.setVisibility(View.GONE);
        llNoNetWork.setVisibility(View.GONE);
        llNone.setVisibility(View.VISIBLE);
    }

    public LoadView setNoData(String text) {
        tvNoData.setText(text);
        viewHintLeft.setVisibility(View.INVISIBLE);
        viewHintRight.setVisibility(View.INVISIBLE);
        return this;
    }


    public static enum EmptyState {
        noData, noNetWork, loading, none
    }

    public LoadView setHide() {
        llLoading.setVisibility(View.INVISIBLE);
        llNoData.setVisibility(View.INVISIBLE);
        llNoNetWork.setVisibility(View.INVISIBLE);
        llNone.setVisibility(View.INVISIBLE);
        return this;
    }
}
